<template>
    <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
        <van-list
            v-model:loading="loading"
            :finished="finished"
            :offset="10"
            finished-text="没有更多了"
            @load="onLoad"
        >
        <div class="item" v-for="(item,key) in list" :key="key">
            <p>{{ item.content }}</p>
            <p>金额：{{item.total}}元</p>
            <p>时间：{{item.createtime_text}}</p>
        </div>
        <!-- <van-back-top :bottom="'80'" /> -->
        </van-list>
    </van-pull-refresh>
</template>

<script setup>
    const {proxy} = getCurrentInstance()

    let business = proxy.$business
    //消费记录列表
    let list = ref([])
    //刷新状态
    let refreshing = ref(false)

    //加载状态
    let loading = ref(false)

    //是否无更多数据
    let finished = ref(false)
    //当前页
    let page = ref(1)

  const onRefresh = async () => {
    // console.log(123)
    //重置当前页
    //重置当前页
    page.value = 1
    //重置列表数据
    list.value = []
    //重置加载状态
    loading.value = true
    //重置加载完成状态
    finished.value = false
    //重新获取数据
    onLoad()
  }

  //列表数据
  const onLoad = async () => 
  {
    //判断是否为加载中的状态
    if(refreshing.value)
    {
        refreshing.value = false
    }

    // loading.value = false
    var params = {
        page:page.value,
        busid:business.value.id
    }

    var result = await proxy.$POST({
        url:'business/recordlist',
        params,
    })

    loading.value = false

    // if(result.code == 0)
    // {
    //     finished.value = false
    //     return false
    // }

    if(result.code == 0)
    {
        // proxy.$fail(result.msg)
        return false
    }
    // 没有更多数据
    if(result.data.list.length == 0)
    {
        finished.value = true
        return false
    }
    // return false
    // console.log(result)

    // 没有更多数据
    
    // return false

    list.value = list.value.concat(result.data.list)
    page.value++
    // console.log(list.value )
    // return false

  }
</script>

<style scoped>
  .item{
    background:#fff;
    width:100%;
    text-indent: 1.5em;
    font-size:1em;
    padding:10px 0;
    border-bottom:1px solid #eaeaea;
  }
</style>